﻿using System;
using CNav.Common;
using CNav.DataEntity;
using CNav.Domain;
using System.Collections.Generic;
using System.Linq;

namespace CNav.Business.Services
{
    public interface IAddressService
    {
        ResponseData<Address> GetAddress(int id);
    }

    public class AddressService : ServiceBase, IAddressService
    {
        public ResponseData<Address> GetAddress(int id)
        {
            var response = new ResponseData<Address>();

            var addressDto = Context.Get<AddressDto>(a => a.ID == id).ToList().FirstOrDefault();
            if (addressDto != null)
            {
                var address = new Address();

                address.ID = addressDto.ID;
                address.CountryID = addressDto.CountryID;
                address.State = addressDto.State;
                address.City = addressDto.City;
                address.Address1 = addressDto.Address1;
                address.Address2 = addressDto.Address2;
                address.PostalCode = addressDto.PostalCode;
                address.CreatedOnUtc = addressDto.CreatedOnUtc;

                response.Data = address;
                return response;
            }

            response.Error = new[] { "Invalid address id provided." };
            return response;
        }
    }
}